﻿using Comm;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace Kinlo.UI.Main.View
{
    /// <summary>
    /// ModifyPasswdView.xaml 的交互逻辑
    /// </summary>
    public partial class ModifyPasswdView : Window
    {
        public ModifyPasswdView()
        {
            InitializeComponent();
        }

        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            try
            {
                if (txtPass.Password == txtPass1.Password)
                {
                    Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
                    if (config.AppSettings.Settings.AllKeys.Contains("SettingPasswd"))
                    {
                        config.AppSettings.Settings["SettingPasswd"].Value = txtPass.Password;
                    }
                    else
                    {
                        config.AppSettings.Settings.Add("SettingPasswd", txtPass.Password);
                    }

                    config.Save(ConfigurationSaveMode.Modified);
                    ConfigurationManager.RefreshSection("appSettings");
                    GlobalValues.Passwd = txtPass.Password;
                    Logger.Info(string.Format("{0} 修改了密码",GlobalValues.EmpNo));
                    MessageBox.Show("保存成功 ", "提示", MessageBoxButton.OK, MessageBoxImage.Information);
                    this.Close();
                }
                else
                {
                    MessageBox.Show("密码不一致,请重新输入", "错误");
                } 
            }
            catch (Exception ex)
            {
                MessageBox.Show(String.Format("录入失败 {0}", ex.Message), "错误", MessageBoxButton.OK, MessageBoxImage.Error);
            }    
            
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            this.Close();
        }
    }
}
